package com.business.wechat.handler;

import java.util.Map;

import org.springframework.stereotype.Component;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;

/**
 * 转发客户消息给客服Handler
 *
 * Created by FirenzesEagle on 2016/7/27 0027. Email:liumingbo2008@gmail.com
 */
@Component
public class MsgHandler extends AbstractHandler {
	@Override
	public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
			WxSessionManager sessionManager) throws WxErrorException {
		WxMpTemplateMessage wt = new WxMpTemplateMessage();
		wt.setToUser(wxMessage.getFromUser());
		wt.setTemplateId("CuYbG89jvNb8XPGFJpwTyPMj3D2-pGPerZN-Ei2iPpw");
		String root = null;// ApplicationUtils.getSettingProperty("server.domain-url");
		wt.setUrl(root + "/platform/wechat/platform/getOpenidRedirect.do");
		WxMpTemplateData d = new WxMpTemplateData();
		d.setName("11");
		d.setValue("22");
		wt.addData(d);
		weixinService.getMpService().getTemplateMsgService().sendTemplateMsg(wt);


		return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().fromUser(wxMessage.getToUser())
				.toUser(wxMessage.getFromUser()).build();
	}

}
